
import { Sdk_Platform, WX_AD_CONFIG } from '../../frame/constants';
cc.Class({
    extends: cc.Component,

    properties: {
        bottom_node: cc.Node
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },

    // update (dt) {},

    initPage() {
    },

    updatePage() {
        this.adSwitch(true)
        this.scheduleOnce(this.closeServer, 2.5)
    },

    closeUI() {
        for (let j = (this.bottom_node.children.length); j > 0; j--) {
            this.bottom_node.children[j - 1].getComponent('scrollAd').clearItem()
            he.pool.putElement('scrollAd', this.bottom_node.children[j - 1])
        }
    },

    closeServer() {
        this.uiBase.closePage()
    },

    adSwitch(status) {
        if (status) {
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    if (!common.showAd) return
                    he.ad.getTdAdJson(WX_AD_CONFIG.tmIcon[10], this.bottomSet.bind(this))
                    break
            }
        } else {
            //  关掉广告
        }
    },

    bottomSet(config) {
        if (config.isOpen) {
            let pre = he.pool.getElement('scrollAd')
            pre.parent = this.bottom_node
            pre.getComponent('scrollAd').init(config.creatives)
        }
    },
});
